<template>
	<view class="">
		<view class="d-flex flex-column align-center pt-3">
			<block v-if="factory_info_data.status == 0">
				<view class="tongguo-no" @tap="tongguo">点击审核通过</view>
			</block>
			<block v-else-if="factory_info_data.status == 1">
				<view class="tongguo-yes">审核已通过</view>
			</block>
			<block v-else>
				<view style="height: 75rpx;" >  </view>
			</block>
		</view>
		<!-- 商家信息 -->
		<FacInfoModify @factory_info="factory_info" :factory_info_data="factory_info_data" :modify="modify" :factory_id="this.factory_id" :scrollH="scrollH" class="pt-2" />
		<facInfo :factory_info_data="factory_info_data" class="pl-5 pr-5" />

		<!-- 员工列表 -->
		<admin-staff-list :staff_list_data="staff_list_data" :activity_id="activity_id" :status="status" class="pl-5 pr-5" />
			
		<view class="top" :style="{'display':(flag===true? 'block':'none')}">
			<uni-icons class="topc" type="arrowthinup" size="30" @click="top"></uni-icons>
		</view>

	</view>
</template>

<script>
	import adminStaffList from '@/components/admin/admin_staff_list.vue'
	import uniIcons from '../../components/common/uni-icons/uni-icons.vue'
	export default {
		components: {
			adminStaffList,
			uniIcons,
		},
		data() {
			return {
				scrollH: 100,
				ygimg: '../../static/index.png',
				gcimg: '../../static/my.png',
				factory_info_data: [],
				modify: {
					boss_name: '',
					boss_tel: '',
					name: '',
					address: '',
					phone: '',
					head_url: '',
					code_url: ''
				},
				staff_list_data: [],
				factory_id: 0,
				activity_id: 0,
				staff_id: 0,
				staff_name: '',
				page: 1,
				flag: false,
				status: 'nomore',
			}
		},
		onLoad(e) {
			this.factory_info_data.status = e.status
			this.factory_id = e.factory_id
			this.activity_id = e.activity_id
			this.$comm.appLogin(user_info=>{
				this.factory_info()
				this.staff_list()
				this.get_scrollH()
			})
		},
		onPullDownRefresh() {
			this.loaddata()
		},
		onReachBottom() {
			// this.staff_list()
		},

		methods: {
			//获取可视区域高度
			get_scrollH() {
				uni.getSystemInfo({
					success: (res) => {
						this.scrollH = res.windowHeight - uni.upx2px(270)
						// console.log(res.windowHeight, '可视区域高度',this.scrollH)
					}
				})
			},
			
			tongguo() {
				// console.log(this.factory_info_data.status, this.factory_id,99)
				if (this.factory_info_data.status == 1) {
					uni.showToast({
						title: '审核已通过，请勿重复点击',
						icon: 'none'
					})
					return
				}
				this.$comm.request({
					url: 'api/check_factory',
					method: 'POST',
					data: {
						factory_id: this.factory_id,
					},
					success: res => {
						console.log(res,'api/check_factory')
						if (res.data.code == 201) {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							})
							return
						}
						uni.showToast({
							title: res.data.msg,
							icon: 'success',
							duration: 2000,
						});
						this.factory_info_data.status = 1;
						// uni.navigateBack({
						// 	delta: 1,
						// })
						// this.$emit('factory_list()')
						// this.$set(this.factory_list_data,'status',1)
					}
				});
			},
			
			//获取商家信息
			factory_info(id) {
				var id = this.factory_id
				// console.log(id)
				this.$comm.request({
					url: 'api/factory_info?factory_id=' + id,
					method: 'GET',
					data: {
						factory_id: id
					},
					success: res => {
						console.log(res, 'api/factory_info');
						this.factory_info_data = res.data.result;
						this.modify.boss_name = res.data.result.boss_name
						this.modify.boss_tel = res.data.result.boss_tel
						this.modify.name = res.data.result.name
						this.modify.phone = res.data.result.tel
						this.modify.address = res.data.result.address
						this.modify.head_url = res.data.result.head_url
						this.modify.code_url = res.data.result.code_url
					}
				});
			},

			//获取员工列表
			staff_list(id) {
				// if (this.status == 'nomore') {
				// 	return
				// }
				this.$comm.request({
					url: 'api/activity_staff_list',
					method: 'GET',
					data: {
						factory_id: this.factory_id,
						// page: this.page++,
						activity_id: this.activity_id,
					},
					success: res => {
						console.log(res, 'api/activity_staff_list');
						this.staff_list_data = res.data.result
						// this.staff_list_data = this.staff_list_data.concat(list);
						/* if (list.length < 10) {
							this.status = 'nomore'
						} */
						/* let data = this.staff_list_data
						data.sort(compareDown("invite_count"));
						function compareDown(propertyName) { // 降序排序
							if ((typeof data[0][propertyName]) != "number") { // 属性值为非数字
								return function(object1, object2) {
									var value1 = object1[propertyName];
									var value2 = object2[propertyName];
									return value2.localeCompare(value1);
								}
							}
							else {
								return function(object1, object2) { // 属性值为数字
									var value1 = object1[propertyName];
									var value2 = object2[propertyName];
									return value2 - value1;
								}
							}
						} */
					}
				});
			},

			// 下拉刷新
			loaddata() {
				this.page = 1
				this.status = 'more'
				this.staff_list_data = []
				this.staff_list()
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 1000);
			},

			//回到顶部
			top() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			onPageScroll(e) { //根据距离顶部距离是否显示回到顶部按钮
				if (e.scrollTop > 600) { //当距离大于600时显示回到顶部按钮
					this.flag = true
				} else { //当距离小于600时显示回到顶部按钮
					this.flag = false
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/common/main.css';
	@import  '@/common/zcm-main.css';
	
	page {
		background-color: #f1f1f1;
		font-size: 30rpx;
	}

	.head-text {
		color: #ffffff;
		line-height: 2.5;
		background-color: #475dfc;
		width: 300rpx;
		text-align: center;
		border-radius: 50rpx;
	}
	
	.tongguo-yes {
		color: #ffffff;
		line-height: 2.5;
		background-color: #5fb256;
		width: 400rpx;
		text-align: center;
		border-radius: 50rpx;
	}
	
	.tongguo-no {
		color: #ffffff;
		line-height: 75rpx;
		// line-height: 2.5;
		background-color: #A40000;
		width: 400rpx;
		text-align: center;
		border-radius: 50rpx;
	}

	.tabbar {
		width: 100%;
		height: 98rpx;
		position: fixed;
		bottom: 0;
		display: flex;
		justify-content: space-around;
		padding: 10rpx 0 0rpx 0;
		text-align: center;
		border-top: solid 2rpx #ccc;
		background-color: #fff;
		
		.tabbarimg{
			width: 55rpx; 
			height: 55rpx;
		}
		
		.tabbartext{
			font-size: 20rpx; 
			margin-top: -10rpx;
		}
	}

	.top {
		position: relative;
		display: none;
		/* 先将元素隐藏 */
	}

	.topc {
		position: fixed;
		right: 0;
		// background: #F0F0F0;
		bottom: 30rpx;
		right: 30rpx;
		background-color: #FFF;
		border: solid 2rpx #475dfc;
		border-radius: 100rpx;
		height: 80rpx;
		width: 80rpx;
		line-height: 80rpx;
	}
</style>
